package com.yangyang.ralearn.client.rlclient;

import java.util.List;

import com.yangyang.ralearn.common.JEnvironment;
import com.yangyang.ralearn.common.entity.base.AbstractDomainPredicate;
import com.yangyang.ralearn.common.exception.ErrorActionException;
import com.yangyang.ralearn.common.exception.ReachGoalException;
import com.yangyang.ralearn.server.ServerManager;

public class RLMultiThreadAgentHandler implements IRLAgentHandler {

	private int groupId, simulatorId;

	public RLMultiThreadAgentHandler() {

	}

	public void initFeature(int groupId, int simulatorId) {
		this.groupId = groupId;
		this.simulatorId = simulatorId;
	}

	public RLMultiThreadAgentHandler(int groupId, int simulatorId) {
		super();
		this.groupId = groupId;
		this.simulatorId = simulatorId;
	}

	@Override
	public JEnvironment init(String domainFile, String problemFile) {
		// TODO Auto-generated method stub
		ServerManager.instance().newGroup(groupId, domainFile, simulatorId,
				problemFile, null);
		return ServerManager.instance().getEnvironmentById(groupId);
	}

	@Override
	public List<AbstractDomainPredicate> observe() {
		// TODO Auto-generated method stub
		return ServerManager.instance().getSimulatorById(groupId, simulatorId)
				.observe();
	}

	@Override
	public boolean canDo(String line) {
		// TODO Auto-generated method stub
		return ServerManager.instance().getSimulatorById(groupId, simulatorId)
				.canDo(line);
	}

	@Override
	public void doAction(String line) throws ReachGoalException,
			ErrorActionException {
		// TODO Auto-generated method stub
		ServerManager.instance().getSimulatorById(groupId, simulatorId)
				.doAction(line);
	}

	@Override
	public void nextProblem(String problemFile) {
		// TODO Auto-generated method stub
		ServerManager.instance().nextProblem(groupId, simulatorId, problemFile);
	}

}
